package xyz.labmem.base.sys.config

import cn.dev33.satoken.stp.StpInterface
import org.springframework.stereotype.Component
import xyz.labmem.base.sys.context.AuthRedisService
import xyz.labmem.base.sys.module.auth.service.AuthService

/**
 * @Author lty
 * @Date 2021/12/17 15:37
 */
@Component
class SecurityAuthority(
    private var authRedisService: AuthRedisService,
    private var authService: AuthService
) : StpInterface {

    override fun getPermissionList(loginId: Any, loginType: String): List<String> {
        var per = authRedisService.getUserPermission(loginId.toString())
        if (per == null) {
            per = authService.updateUserPermission(loginId.toString())
        }
        return per
    }

    override fun getRoleList(loginId: Any, loginType: String): List<String> {
        var role = authRedisService.getUserRole(loginId.toString())
        if (role == null) {
            role = authService.updateUserRole(loginId.toString())
        }
        return role
    }

}